home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 April / EnigmA AMIGA RUN 17 (1997)(G.R. Edizioni)(IT)[!][issue 1997-04][EAR-CD].iso / EARCD / comm / bbs / Hydra11s.lha / HBBS / Source / Misc / TecLisMailSys / MailDoor.c < prev    next >
C/C++ Source or Header  |  1996-06-25  |  6KB  |  278 lines

  1. /*
  2.  
  3.  TecLis Mail System.   by TecLis. Started 13 Jun 1995. ®1995 TecLis Productions.
  4.  
  5.  
  6.  Params passed to Main are :
  7.  
  8.    InitialScan   : Only parse the mail area ONCE.  Save the messages available to
  9.                  : to user.
  10.  
  11.    MAILSCAN      : Scans selected conferences (default = All) for messages..
  12.                  : Should display a list of them (per conf.)
  13.                  : Check for :- To User, Users Groups, All
  14.  
  15.    ENTERMESSAGE  : Enters - To, Subject (Date/Time Stored), Private (Depends on user)
  16.  
  17.    READMESSAGE   :
  18.  
  19.    ENTERCOMMENT  L Enter Message to Sysop/CoSysop
  20.  
  21.  
  22.   todo
  23.   ====
  24.  
  25.   allow typing of message number at the mailscan prompt and when reading a message
  26.  
  27.   allow use of message number after the R command (E.G.  R 21 to read message 21)
  28.  
  29.   bugs
  30.   ====
  31.  
  32.   if you have a message with blank lines they are stripped when it is displayed..
  33.  
  34.   check for writing to the same person more than once.. (Hydra,Hydra is currently valid..)
  35.  
  36.   typing R in a conference with NO mail brings up the message
  37.     "Sorry <user>, No Messages  have been sent to you"
  38.   when it should read:
  39.     "Sorry Hydra, there is no mail in this conference"
  40.  
  41.   leaves LOADS of memory behind! check all Alloc and Free pairs..
  42.  
  43.  
  44. */
  45.  
  46. #define MAILSYSMAIN
  47.  
  48. #include <dos/dos.h>
  49. #include <exec/types.h>
  50. #include <exec/memory.h>
  51. #include <clib/dos_protos.h>
  52. #include <clib/exec_protos.h>
  53. #include <clib/alib_protos.h>
  54.  
  55. #include <stdlib.h>
  56. #include <string.h>
  57. #include <stdio.h>
  58. #include <ctype.h>
  59. #include <time.h>
  60.  
  61.  
  62. #ifdef __SASC
  63. int CXBRK(void) { return(0); }
  64. int _CXBRK(void) { return(0); }
  65. void chkabort(void) {}
  66. #endif
  67.  
  68. #include <HBBS/ANSI_Codes.h>
  69. #include <HBBS/Defines.h>
  70. #include <HBBS/types.h>
  71. #include <HBBS/structures.h>
  72. #include <HBBS/hbbscommon_protos.h>
  73. #include <HBBS/hbbscommon_pragmas.h>
  74. #include <HBBS/Hbbsnode_protos.h>
  75. #include <HBBS/Hbbsnode_pragmas.h>
  76.  
  77. #include "maildoor.h"
  78. #include "mailscan.h"
  79. #include "mailread.h"
  80. #include "mailedit.h"
  81.  
  82. ULONG __stack = 20000;
  83.  
  84. struct Library *HBBSCommonBase=NULL;
  85. struct Library *HBBSNodeBase=NULL;
  86.  
  87. struct BBSGlobalData *BBSGlobal=NULL;
  88. struct NodeData *N_ND=NULL;
  89. int N_NodeNum=-1;
  90.  
  91. static VOID cleanup(ULONG num)
  92. {
  93.   if (HBBSNodeBase)
  94.   {
  95.     HBBS_CleanUpDoor();
  96.     CloseLibrary (HBBSNodeBase);
  97.   }
  98.  
  99.   if (HBBSCommonBase)
  100.   {
  101.     HBBS_CleanUpCommon();
  102.     CloseLibrary (HBBSCommonBase);
  103.   }
  104.  
  105.   if (num) printf("Door Error = %d\n",num);
  106.  
  107.   exit(0);
  108. }
  109.  
  110. static VOID init(char *name)
  111. {
  112.   if(!(HBBSCommonBase = OpenLibrary("HBBSCommon.library",0)))
  113.   {
  114.     cleanup(1);
  115.   }
  116.  
  117.   if (!(HBBS_InitCommon()))
  118.   {
  119.     cleanup(2);
  120.   }
  121.  
  122.   if(!(HBBSNodeBase = OpenLibrary("HBBSNode.library",0)))
  123.   {
  124.     cleanup(3);
  125.   }
  126.  
  127.   if (!(HBBS_InitDoor(N_NodeNum,name)))
  128.   {
  129.     cleanup(4);
  130.   }
  131.   SetProgramName(name);
  132. }
  133.  
  134. BOOL MYDOOR_SetupGlobals( int argc, char *argv[] )
  135. {
  136.   int loop, n;
  137.  
  138.   // Setup Paths for Mail System
  139.  
  140.   if( MSys_MainPath = AllocVec( MAX_PATH_LENGTH, MEMF_PUBLIC|MEMF_CLEAR ) )
  141.   {
  142.     loop = strlen( argv[0] )-1;
  143.  
  144.     while( (argv[0][loop] != '/') && (argv[0][loop] != ':' ) ) loop--;
  145.  
  146.     for( n = 0; n <= loop; n++ ) MSys_MainPath[n] = argv[0][n] ;
  147.  
  148.   }
  149.   else
  150.   {
  151.     // Fucked UP!
  152.     return( FALSE );
  153.   }
  154.  
  155.   return( TRUE );
  156. }
  157.  
  158. void MYDOOR_ClearGlobals( void )
  159. {
  160.   if( MSys_MainPath ) FreeVec( MSys_MainPath );
  161. }
  162.  
  163. void MYDOOR_DisplayDoorHelp( void )
  164. {
  165.   DOOR_WriteText( "No operation requested!\r\n" );
  166. }
  167.  
  168. void MYDOOR_DisplayTecLisMailHeader( void )
  169. {
  170.   char outstr[BUFFER_LENGTH];
  171.  
  172.   sprintf( outstr, "%s%sTecLis Mail Reader.  ©1995 TecLis Productions.                     By TecLis/TEP%s%s\r\n\r\n", ANSI_FG_YELLOW, ANSI_BG_BLUE, ANSI_FG_WHITE, ANSI_BG_BLACK );
  173.   DOOR_WriteText( outstr );
  174. }
  175.  
  176. int MYDOOR_GetOptionNumber( int argc, char *argv[] )
  177. {
  178.   int option = MSys_OPT_OPTUNKNOWN;
  179.   BOOL Found = FALSE;
  180.  
  181.   if( N_ND->ActiveDoor->SystemOptions )
  182.   {
  183.     if( iposition( "MAILSCAN", N_ND->ActiveDoor->SystemOptions ) >=0 )
  184.     {
  185.       Found = TRUE;
  186.       option = MSys_OPT_MAILSCAN;
  187.     }
  188.     else
  189.     {
  190.       if( iposition( "READMESSAGES", N_ND->ActiveDoor->SystemOptions ) >=0 )
  191.       {
  192.         Found = TRUE;
  193.         option = MSys_OPT_READMESSAGE;
  194.       }
  195.       else
  196.       {
  197.         if( iposition( "ENTERMESSAGE", N_ND->ActiveDoor->SystemOptions ) >=0 )
  198.         {
  199.           Found = TRUE;
  200.           option = MSys_OPT_ENTERMESSAGE;
  201.         }
  202.         else
  203.         {
  204.           if( iposition( "ENTERCOMMENT", N_ND->ActiveDoor->SystemOptions ) >=0 )
  205.           {
  206.             Found = TRUE;
  207.             option = MSys_OPT_ENTERCOMMENT;
  208.           }
  209.         }
  210.       }
  211.     }
  212.   }
  213.   return( option );
  214. }
  215.  
  216. void DoorMain( int argc,char *argv[] )
  217. {
  218.   char outstr[100];
  219.  
  220.  
  221.   if( MYDOOR_SetupGlobals( argc, argv ) )
  222.   {
  223.     if( argc < 2 )
  224.       MYDOOR_DisplayDoorHelp();
  225.     else
  226.     {
  227.       switch( MYDOOR_GetOptionNumber( argc, argv ) )
  228.       {
  229.         case MSys_OPT_OKAY:
  230.           sprintf( outstr, "No operation requested!\r\n" );
  231.           DOOR_WriteText( outstr );
  232.           break;
  233.         case MSys_OPT_MAILSCAN:
  234.           MYDOOR_DoMailScan( argc, argv );
  235.           break;
  236.         case MSys_OPT_ENTERMESSAGE:
  237.           MYDOOR_DoEnterMessage( NULL );
  238.           break;
  239.         case MSys_OPT_READMESSAGE:
  240.           MYDOOR_DoReadMail( argc, argv );
  241.           break;
  242.         case MSys_OPT_OPTUNKNOWN:
  243.           sprintf( outstr, "Option unknown!\r\n" );
  244.           DOOR_WriteText( outstr );
  245.           break;
  246.         case MSys_OPT_ENTERCOMMENT:
  247.           MYDOOR_DoEnterMessage( "SYSOP" );
  248.           break;
  249.       }
  250.     }
  251.   }
  252.   else
  253.   {
  254.     DOOR_WriteText( "There were problems\r\n" );
  255.   }
  256.   MYDOOR_ClearGlobals();
  257.  
  258. }
  259.  
  260. int main(int argc,char *argv[])
  261. {
  262.   if (sscanf(argv[1],"%d",&N_NodeNum)==0)
  263.   {
  264.     printf("Invalid/No Paramaters for door!\n");
  265.     exit (20);
  266.   }
  267.   init("TecLis Mail System");
  268.  
  269.   if (BBSGlobal=HBBS_GimmeBBS())
  270.   {
  271.     if (N_ND=HBBS_NodeDataPtr(N_NodeNum)) // this should not fail in normal circumstances..
  272.     {
  273.       DoorMain(argc,argv);
  274.     }
  275.   }
  276.   cleanup(0);
  277. }
  278.